<template>
  <div>
    <el-container>
      <el-aside width="200px">
        <d-list @select="handleSelect"></d-list>
      </el-aside>
      <el-main style="overflow: hidden;">
        <el-row>
          <el-col
            :span="5"
            :offset="1"
            v-for="(key,value) in showdevice"
            :key="value"
            style="height:220px; position: relative;"
          >
            <el-card
              :body-style="{ padding: '0px' ,'text-align':'center',height:'160px', background: '#f7f7f7',
    border: '1px solid #1661b9',
    'line-height': '160px','object-fit':'contain' }"
            >
              <img
                style="object-fit: contain;
                          width: 100%;
                          height: 100%;
                          padding: 2px;
                          box-sizing: border-box;"
                :src="key.src"
                alt
                @click="showdeviceinfo(key)"
                :name="value"
              />
            </el-card>
            <div
              style="position: absolute;
                            bottom: 30px;text-align:center; font-size:12px;width: 100%;"
                            :class="{'active':deviceBaseInfo===key}"
            >
              <span>{{value}}</span>
            </div>
          </el-col>
        </el-row>
        <div
          v-show="drawer"
          ref="deviceBaseInfo"
          style="position: absolute;
    right: 0;
    width: 30vw;
    background: #fff;
    height: 100%;
    top: 0;
    border: 1px solid #eee;
    border-radius: 5px;
    box-shadow: 0px 1px 6px 5px #eee;
    box-sizing: border-box;"
    :style="{'right':drawerright+'px','top':drawertop+'px'}"
        >
          <div style="border:1px solid #eee;height:40px" 
          @mousemove="deviceBaseInfoHandleMove($event)">
            <el-row >
              <el-col
                :span="22"
                
                style="    line-height: 40px;padding-left:20px"
              >
              <span >{{deviceBaseInfo.name}}</span>
                  <el-button @click="HandleEdit">编辑</el-button>
                  <el-button>删除</el-button>
              </el-col>
              <el-col :span="2">
                <el-button @click="CloseDevice" class="el-icon-close" style="float:right"></el-button>
              </el-col>
            </el-row>
          </div>
          <div
            style="max-height:calc(100% - 42px); padding-left:10px;overflow-y:auto;padding-top:20px;box-sizing: border-box;"
          >
          <el-row>
                        <el-col :span="24" >
              <el-button-group
                style="width:calc(100% - 10px);box-sizing: border-box;padding-right: 30px;
    border: 1px solid #eee;
    line-height: 40px;
    padding-left:10px;
    margin:10px 0;
    border-radius: 5px"
              >
                <el-tag>当前状态：</el-tag>
                <span>启用中</span>
                <!-- <el-button label="right" style="width:auto">{{item.value||"&nbsp;"}}</el-button> -->
              </el-button-group>
                            <el-button-group
                style="width:calc(100% - 10px);box-sizing: border-box;padding-right: 30px;
    border: 1px solid #eee;
    line-height: 40px;
    padding-left:10px;
    margin:10px 0;
    border-radius: 5px"
              >
                <el-tag>启用时间</el-tag>
                <span>2019-09-18</span>
                <!-- <el-button label="right" style="width:auto">{{item.value||"&nbsp;"}}</el-button> -->
              </el-button-group>
            </el-col>

          </el-row>
            <el-col :span="24" v-for="item in attr" :key="item.name">
              <el-button-group
                style="width:calc(100% - 10px);box-sizing: border-box;padding-right: 30px;
    border: 1px solid #eee;
    line-height: 40px;
    padding-left:10px;
    margin:10px 0;
    border-radius: 5px"
              >
                <el-tag>{{item.name}}：</el-tag>
                <span>{{item.value||"&nbsp;"}}</span>
                <!-- <el-button label="right" style="width:auto">{{item.value||"&nbsp;"}}</el-button> -->
              </el-button-group>
            </el-col>
          </div>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import dList from "./deviceList";
import { fabric } from "@/js/fabric";
import alldevice from "@/js/devicefenlei.js";
import { createdevice1 } from "@/js/deviceloader";
export default {
  components: {
    dList
  },
  data() {
    return {
      fenlei: "",
      deviceinfo: {},
      drawer: false,
      deviceBaseInfo: {},
      drawerright:0,
      drawertop:0
    };
  },
  computed: {
    showdevice() {
      return this.deviceinfo[this.fenlei];
    },
    attr() {
      return this.deviceBaseInfo.attr || {};
    }
  },
  methods: {
    handleSelect(key) {
      this.fenlei = key;
    },
    showdeviceinfo(value) {
      this.deviceBaseInfo = value;
      this.drawer = true;
    },
    CloseDevice() {
      this.deviceBaseInfo = {};
      this.drawer = false;
    },
    deviceBaseInfoHandleMove($event){
        if($event.buttons==1){
            this.$nextTick(()=>{
                this.drawerright=this.drawerright-$event.movementX;
                this.drawertop=this.drawertop+$event.movementY;
            })
        }
    },
    HandleEdit(){
        const _this = this;
        this.$router.push({
            path:"/Demos/staticCanvas",
            query:{
                device:_this.deviceBaseInfo.name
            }
        })
    }
  },
  mounted() {
    const _this = this;
    this.$nextTick(() => {
      for (let item in alldevice) {
        let deviceinfo = {};
        alldevice[item].forEach(ele => {
          ele = ele.default || ele;
          try {
            deviceinfo[ele.name] = createdevice1(ele);
          } catch (e) {
            console.log(ele);
          }
        });
        _this.deviceinfo[item] = deviceinfo;
      }
    });
  }
};
</script>

<style scoped>
.active {
    color: #0a1dad;
    font-size: 16px;
    font-weight: 600;
}
</style>